package com.eight.clientcourse.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eight.clientcourse.service.ClientCrouseService;
import com.eight.clientcourse.vo.CourseVo;
import com.eight.clientcourse.vo.GuanZhuVo;
import com.eight.common.pojo.*;
import com.eight.common.vo.Result;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: qy8-education1
 * @description:
 * @author: 张亚祥
 * @create: 2023-06-02 16:26
 **/
@RestController
@RequestMapping("/core/course")
@ApiModel(value = "课程中心")
public class ClientCourseController {

    @Resource
    private ClientCrouseService clientCrouseService;

    @PostMapping("getAllMenu")
    @ApiOperation("查询课程")
    public Result getAllMenu(){
        List<EduSubject> course = clientCrouseService.findCourse();
        return Result.success(course);
    }
    @PostMapping("/fontFindCourse/{currentSize}/{pageSize}")
    @ApiOperation(value = "课程分类分页条件查询")
    public Result findCourse(@PathVariable Integer currentSize, @PathVariable Integer pageSize, @RequestBody CourseVo courseVo){
        Page<EduCourse> page = clientCrouseService.findPage(currentSize, pageSize,courseVo);
        return Result.success(page);
    }
    @PostMapping("/queryAllCourseAndTeacherName/{id}")
    @ApiOperation(value = "根据课程id查询学生和教师信息")
    public Result queryAllCourseAndTeacherName(@PathVariable String id){
        EduCourse eduCourses = clientCrouseService.queryAllCourseAndTeacherName(id);
        if(eduCourses!=null){
            return Result.success(eduCourses);
        }
        return Result.fail();
    }
    @PostMapping("/queryMemberStatus/{mobile}")
    @ApiOperation(value = "根据课程id和会员id判断当前账号是否为讲师")
    public Result queryMemberStatus(@PathVariable String mobile){
        TbMember tbMember = clientCrouseService.queryMemberStatus(mobile);

        if(tbMember!=null){
            return Result.success(tbMember);
        }
        return Result.fail();
    }
    @PostMapping("/findFavoriteCourse/{courseId}/{memberId}")
    @ApiOperation(value = "渲染页面是否已经收藏")
    public Result findFavoriteCourse(@PathVariable String courseId ,@PathVariable String memberId){
        EduCourse favoriteCourse = clientCrouseService.findFavoriteCourse(courseId, memberId);
        return Result.success(favoriteCourse);
    }
    @PostMapping("addFavoritescourse")
    @ApiOperation(value = "收藏课程")
    public Result addFavoritescourse(@RequestBody TbShoucangCourse tbShoucangCourse){
        int i = clientCrouseService.addFavoritescourse(tbShoucangCourse);
        return Result.success();
    }
    @PostMapping("deleteFavoriteCourse")
    @ApiOperation(value = "取消收藏课程")
    public Result deleteFavoriteCourse(@RequestBody TbShoucangCourse tbShoucangCourse){
        int i = clientCrouseService.deleteFavoriteCourse(tbShoucangCourse);
        return Result.success();
    }
    @PostMapping("insertPlayHistoryByCourseId/{HuiYuanId}/{videoId}")
    @ApiOperation(value = "插入当前视频的观看记录")
    public Result insertPlayHistoryByCourseId(@PathVariable String HuiYuanId,@PathVariable String videoId){
        int i = clientCrouseService.insertPlayHistoryByCourseId(HuiYuanId,videoId);
        return Result.success();
    }
}
